﻿from urllib import request
from urllib import parse
from http import cookiejar
import re
init_url = "http://e.zhbit.com/jsxsd/xk/LoginToXk"
postdata = parse.urlencode({  
	'encoded':'MTMwMjAyMDIxMDE3%%%NTY3ODkxMCo='  
}).encode(encoding='UTF8')
#cookie的处理
cookie_support = request.HTTPCookieProcessor(cookiejar.CookieJar()) 
opener = request.build_opener(cookie_support, request.HTTPHandler)
request.install_opener(opener)

req = request.Request(url = init_url , data = postdata)
req.add_header("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36");
#with语句最重要的事情是可以自动关闭
with request.urlopen(req) as f:
	print('Status:', f.status, f.reason)
	print(f.read().decode('utf-8'))